//
//  WKNetworkTools.h
//  WeKeTang
//
//  Created by ichina on 2017/8/23.
//  Copyright © 2017年 Dezhi Tiancheng Education Technology (Beijing) Co. Ltd. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AFNetworking.h>

@protocol DownloadCompletePercentageDelegate <NSObject>

- (void)completePercentageWithFloat:(CGFloat) progress;

@end

typedef void (^ResponseBlock)(id responseObject);
typedef void (^FinishBlock)(id responseObject);
typedef void (^AFNErrorBlock)(NSError* error);
typedef void (^DownloadBlock)(NSString *filePath);


@interface WKNetworkTools : NSObject

@property (nonatomic,strong) NSString *httpMethod;
@property (nonatomic,assign) BOOL needLogin;
@property (strong,nonatomic) NSMutableDictionary *postDict;
@property (strong,nonatomic) NSMutableDictionary *postFileDict;
@property (nonatomic, weak) id <DownloadCompletePercentageDelegate> delegate;

+ (WKNetworkTools*)shareManger;

- (void)setRequestPost;
//不带提示框的
- (NSURLSessionDataTask*)RunNoneRequest:(NSMutableDictionary *)dict
                                   path:(NSString *)path
                                   tip :(NSString*)tip
                      completionHandler:(ResponseBlock)completionBlock
                           errorHandler:(AFNErrorBlock)errorBlock
                          finishHandler:(FinishBlock)finishBlock;
//带提示框的
- (NSURLSessionDataTask*)RunRequest:(NSMutableDictionary *)dict
                               path:(NSString *)path
                               tip :(NSString*)tip
                  completionHandler:(ResponseBlock)completionBlock
                       errorHandler:(AFNErrorBlock)errorBlock
                      finishHandler:(FinishBlock)finishBlock;
//请求数据
- (NSURLSessionDataTask*)RunRequest:(NSMutableDictionary *)dict
                               path:(NSString *)path
                  completionHandler:(ResponseBlock)completionBlock
                       errorHandler:(AFNErrorBlock)errorBlock
                      finishHandler:(FinishBlock)finishBlock;
- (NSURLSessionDataTask*)RunRequest:(NSMutableDictionary *)dict
                               path:(NSString *)path
                             useSSL:(BOOL)useSSL
                  completionHandler:(ResponseBlock)completionBlock
                       errorHandler:(AFNErrorBlock)errorBlock
                      finishHandler:(FinishBlock)finishBlock;
//下载
- (void)DownloadFileFrom:(NSString *)remoteURL
                  toFile:(NSString *)filePath
       completionHandler:(DownloadBlock)completionBlock
            errorHandler:(AFNErrorBlock)errorBlock;
//上传
- (NSURLSessionDataTask *)uploadDataWithPath:(NSString *)path
                                  parameters:(NSMutableDictionary *)parameters
                                     manager:(AFHTTPSessionManager *)manager
                           completionHandler:(ResponseBlock)completionBlock
                                errorHandler:(AFNErrorBlock)  errorBlock
                               finishHandler:(FinishBlock)finishBlock;
- (void)cancelOperation:(NSURLSessionDataTask *)task;

@end
